import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import { resolve } from 'path'
import vuejsx from '@vitejs/plugin-vue-jsx'

// https://vitejs.dev/config/
export default ({ mode }) => {
  const VITE_BASE_URL = loadEnv(mode, process.cwd()).VITE_BASE_URL
  return defineConfig({
    base: '/nsiLibiary/',
    plugins: [vue(), vuejsx()],
    server: {
      host: true,
      port: 8000,
      cors: true,
      https: false,
      strictPort: true,
      proxy: {
        '/api': {
          target: VITE_BASE_URL,
          changeOrigin: true,
          // 协议 地址 端口
          rewrite: (path: any) => path.replace(/^\/api/, '')
        }
      },
      open: true
    },
    resolve: {
      alias: {
        '@': resolve(__dirname, './src/')
      }
    },
    css: {
      // css预处理器
      // preprocessorOptions: {
      //   scss: {
      // 会为所有的vue文件内的css部分都注入这行代码
      //     additionalData: '@import "src/styles/var.scss";' // 全局公共样式
      //   }
      // }
    },
    optimizeDeps: {
      include: ['element-plus']
    }
  })
}